<?php
include './Classes/PHPExcel.php';
$excel = new PHPExcel();
$objDrawing = new PHPExcel_Worksheet_Drawing();
// 设置文本对齐方式
$excel->getDefaultStyle()->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$excel->getDefaultStyle()->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
$objActSheet = $excel->getActiveSheet();

$letter = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');
$tableheader = array('编号','姓名', '性别', '年龄', '班级', '头像');//表头数据
for($i = 0;$i < count($tableheader);$i++) {
	$excel->getActiveSheet()->setCellValue("$letter[$i]1","$tableheader[$i]");//填充表格表头
	$objActSheet->getColumnDimension("$letter[$i]")->setWidth(28);// 设置表格宽度
}
// 表格数据
$data = array(
	array('小王', '男', '20', 'CS12', '1.jpg'),
	array('小李', '女', '21', 'CS12', '1.jpg'),
	array('小周', '男', '22', 'CS12', '1.jpg'),
	array('小赵', '女武汉市企桥商务服务有限公司', '23', 'CS12', '1.jpg'),
	array('小赵', '女', '23', 'CS12', '1.jpg'),
	array('小赵', '女', '23', 'CS12', '1.jpg'),
	array('小赵', '女', '23', 'CS12', '1.jpg'),
	array('小张', '男', '24', 'CS12', '1.jpg')
);
//填充表格内容
$row = 1;
foreach($data as $k => $v){
	$row++;
	$excel->getActiveSheet()->getRowDimension($row)->setRowHeight(80);//设置表格高度
	foreach($v as $kk => $vv){
		$cell = $kk + 1;
		if($kk == 4){
			$objDrawing = new PHPExcel_Worksheet_Drawing();//实例化插入图片类
			$objDrawing->setPath($vv);//设置图片路径
			$objDrawing->setHeight(100);//设置图片高度
			// $objDrawing->setWidth(100);
			$objDrawing->setCoordinates("$letter[$cell]$row");//设置图片要插入的单元格
			//设置图片所在单元格的格式
			$objDrawing->setOffsetX(4);
			$objDrawing->setOffsetY(4);
			$objDrawing->setRotation(20);
			$objDrawing->getShadow()->setVisible(true);
			$objDrawing->getShadow()->setDirection(50);
			$objDrawing->setWorksheet($excel->getActiveSheet());
			continue;
		}
		$excel->getActiveSheet()->setCellValue("A".$row,$row - 1);//填充表格编号
		$excel->getActiveSheet()->setCellValue("$letter[$cell]$row", $vv);//填充表格除编号和图片的字段
	}
}

$write = new PHPExcel_Writer_Excel5($excel);
$filename = 'index_write_img.xls';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:must-revalidate, post-check=0, pre-check=0");
header("Content-Type:application/force-download");
header("Content-Type:application/vnd.ms-execl");
header("Content-Type:application/octet-stream");
header("Content-Type:application/download");;
header("Content-Disposition:attachment;filename=" . $filename);
header("Content-Transfer-Encoding:binary");
$write->save('php://output');
?>